﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SwiftMVVM.ViewModel;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace MineSweeper.Data
{
    //implementing DependentBindingObject for textboxes in Statistics window
    public abstract class Difficulty : BindingObject
    {
        public DifficultyManager Parent { get; private set; }

        /// <summary>
        /// Object represents a difficulty, properties have the values of given settings at time of creation only 
        /// </summary>
        /// <param name="roundsPlayed">setting for rounds played</param>
        /// <param name="roundsWon">setting for rounds won</param>
        /// <param name="winStreak">setting for longest win streak</param>
        /// <param name="loseStreak">setting for longest loss streak</param>
        /// <param name="currentStreak">setting for current streak</param>
        /// <param name="winPercent">setting for percent of wins</param>
        /// <param name="difName">string of current difficulty</param>
        /// <returns></returns>
        public Difficulty(DifficultyManager parent, int roundsPlayed, int roundsWon, int winStreak, int loseStreak, int currentStreak, decimal winPercent, string difName, System.Collections.ArrayList times)
        {
            this.Parent = parent;
            Played = roundsPlayed;
            Wins = roundsWon;
            WinPercent = winPercent;
            WinStreak = winStreak;
            LossStreak = loseStreak;
            Name = difName;
            Current = currentStreak;
            ArrayTimes = times;
            Times = new ObservableCollection<int>();

            for (int i = 0; i < times.Count; i++)
            {
                Times.Add((int)ArrayTimes[i]);
            }
        }

        public static Difficulty Create()
        {
            return (Difficulty)NotifyProxyTypeManager.Allocate<Difficulty>();
        }

        /// <summary>
        /// Object represents a difficulty, properties have the values of given settings at time of creation only 
        /// </summary>
        /// <param name="roundsPlayed">setting for rounds played</param>
        /// <param name="roundsWon">setting for rounds won</param>
        /// <param name="winStreak">setting for longest win streak</param>
        /// <param name="loseStreak">setting for longest loss streak</param>
        /// <param name="currentStreak">setting for current streak</param>
        /// <param name="winPercent">setting for percent of wins</param>
        /// <param name="difName">string of current difficulty</param>
        /// <returns></returns>
        internal static Difficulty Create(DifficultyManager parent, int roundsPlayed, int roundsWon, int winStreak, int loseStreak, int currentStreak, decimal winPercent, string difName, System.Collections.ArrayList times)
        {
            return (Difficulty)NotifyProxyTypeManager.Allocate<Difficulty>(parent, roundsPlayed, roundsWon, winStreak, loseStreak, currentStreak, winPercent, difName, times);
        }

        // Attribute NotificationProperty to update textboxes in Statistics window after a reset
        [NotificationProperty]
        public virtual string Name { get; set; }

        [NotificationProperty]
        public virtual int Played { get; set; }

        [NotificationProperty]
        public virtual int Wins { get; set; }

        [NotificationProperty]
        public virtual decimal WinPercent { get; set; }

        [NotificationProperty]
        public virtual int WinStreak { get; set; }

        [NotificationProperty]
        public virtual int LossStreak { get; set; }

        [NotificationProperty]
        public virtual int Current { get; set; }

        [NotificationProperty]
        public virtual ObservableCollection<int> Times { get; set; }

        [NotificationProperty]
        public virtual System.Collections.ArrayList ArrayTimes { get; set; }

    }
}
